package com.smartsystem.modules.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smartsystem.modules.system.entity.SysRole;
import com.smartsystem.modules.system.mapper.SysRoleMapper;
import com.smartsystem.modules.system.mapper.SysUserRoleMapper;
import com.smartsystem.modules.system.service.SysRoleService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * 角色表Service实现类
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
    
    @Resource
    private SysRoleMapper sysRoleMapper;
    
    @Resource
    private SysUserRoleMapper sysUserRoleMapper;
    
    @Override
    public List<SysRole> findByUserId(Long userId) {
        // 查询用户拥有的角色ID
        List<Long> roleIds = sysUserRoleMapper.findRoleIdsByUserId(userId);
        if (roleIds.isEmpty()) {
            return List.of();
        }
        // 根据角色ID查询角色信息
        return sysRoleMapper.selectBatchIds(roleIds);
    }
}